/*
 * @Author: szx
 * @Date: 2022-03-13 10:31:28
 * @LastEditTime: 2022-03-13 10:36:48
 * @Description:
 * @FilePath: \leetcode\6000-6100\6031\6031.js
 */
/**
 * @param {number[]} nums
 * @param {number} key
 * @param {number} k
 * @return {number[]}
 */
var findKDistantIndices = function (nums, key, k) {
    const arr = [];
    for (let i = 0; i < nums.length; i++) {
        if (key == nums[i]) {
            arr.push(i);
        }
    }
    const res = [];
    for (let i = 0; i < nums.length; i++) {
        for (let j = 0; j < arr.length; j++) {
            if (Math.abs(arr[j] - i) <= k) {
                res.push(i);
                break;
            }
        }
    }
    return res;
};
console.log(findKDistantIndices([3, 4, 9, 1, 3, 9, 5], 9, 1));
console.log(findKDistantIndices([2, 2, 2, 2, 2], 2, 2));
